<?php
namespace app\api\controller;
use think\Db;
require_once EXTEND_PATH . "wxpay/lib/WxPay.Api.php";
require_once EXTEND_PATH . "wxpay/lib/WxPay.Data.php";
require_once  EXTEND_PATH . "wxpay/WxPay.Config.php";

class Face extends \WxPayDataBase
{
    public function __construct(\WxPayConfig $config)
    {
        $this->values['appid'] = $config->GetAppId();
        $this->values["mch_id"] =$config->GetMerchantId();
        $this->values["version"] ="1";
        $this->values["sign_type"] = $config->GetSignType();
        $this->values["store_id"] ="allsamestoreid";
        $this->values["store_name"] ="统一名字";
        $this->values["device_id"] ="allsamedeviceid";
        $this->values["nonce_str"]=\WxPayApi::getNonceStr();
    }

    public function SetRawdata($value)
    {
        $this->values['rawdata'] = $value;
    }
    public function GetRawdata()
    {
        return $this->values['rawdata'];
    }
    public function IsRawdataSet()
    {
        return array_key_exists('rawdata', $this->values);
    }

    public function SetNow()
    {
        $this->values['now']=time();
    }
    public function SetSub_mchid($mchid)
    {
        $this->values['sub_mch_id']=$mchid;
    }
    public function GetNow()
    {
        return $this->values['now'];
    }
    public function IsNowSet()
    {
        return array_key_exists('now', $this->values);
    }
    public function getAuthInfo(){
//        $rawdata=file_get_contents("php://input");
//        $rawdata=str_replace("rawdata=","",$rawdata);
//        $rawdata=rawurldecode($rawdata);
        $rawdata=$_POST['rawdata'];
        $config=new \WxPayConfig();
        $request=new Face($config);
        $request->SetRawdata($rawdata);
        $mchid = Db::table('up_shop_device')
            ->where('shop_device_id',$_POST['device_info'])
            ->value('shop_mchid');
        $request->SetSub_mchid($mchid);
        $request->SetNow();
        $request->SetSign($config);
        $response = \WxPayApi::postXmlCurl($config, $request->ToXml(), "https://payapp.weixin.qq.com/face/get_wxpayface_authinfo", false, "5");
        echo $response;
    }
}